package com.chao.stucture.bitMap;

import java.util.BitSet;

/**
 * @author : Rookie
 * @description : 位图
 * @date : 2023/7/30
 */
public class BitMapDemo {

    public static void main(String[] args) {
        // 10亿个QQ号
        int totalQQNumbers = 1000000000;
        BitSet bitSet = new BitSet(totalQQNumbers);
        // 判断某个QQ号是否在线
        int qqNumberToCheck = 123456;
        bitSet.set(qqNumberToCheck);
        boolean isOnline = bitSet.get(qqNumberToCheck);
        System.out.println("QQ号" + qqNumberToCheck + "是否在线：" + isOnline);

        // 统计在线的QQ号数量
        int onlineCount = bitSet.cardinality();
        System.out.println("在线QQ号数量：" + onlineCount);

        // 清除某个QQ号的在线状态
        int offlineQQNumber = 123456;
        bitSet.clear(offlineQQNumber);

        boolean isOnline2 = bitSet.get(qqNumberToCheck);
        System.out.println("QQ号" + qqNumberToCheck + "是否在线：" + isOnline2);
    }
}
